package com.whfc.emp.manager.impl;

import com.whfc.common.geometry.Point;
import com.whfc.common.third.map.MapApi;
import com.whfc.common.third.map.MapLoc;
import com.whfc.emp.dao.AppFaceGateMapper;
import com.whfc.emp.entity.AppFaceGate;
import com.whfc.emp.entity.AppFaceGateConfig;
import com.whfc.emp.manager.FaceGateManager;
import com.whfc.emp.param.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description 离线闸机
 * @Author hw
 * @Date 2021/1/27 14:20
 * @Version 1.0
 */
@Service("faceGateManagerImpl")
public class FaceGateManagerImpl implements FaceGateManager {

    @Autowired
    private AppFaceGateMapper appFaceGateMapper;

    @Autowired
    private MapApi mapApi;

    @Override
    public void info(AppFaceGateConfig appFaceGateConfig) {

    }

    @Override
    public void add(AppFaceGateAddParam request) {
        String deviceKey = request.getDeviceKey();
        String name = request.getName();
        Integer deptId = request.getDeptId();
        Point point = request.getPoint();

        AppFaceGate record = new AppFaceGate();
        record.setDeviceKey(deviceKey);
        record.setDeptId(deptId);
        record.setName(name);
        record.setDirection(request.getDirection());
        record.setPlatform(request.getPlatform());
        // 增加闸机位置信息
        if (point != null) {
            Double lat = point.getLat();
            Double lng = point.getLng();
            MapLoc loc = mapApi.geocode(lng, lat);
            record.setLng(lng);
            record.setLat(lat);
            record.setAddress(loc.getAddress());
        }
        appFaceGateMapper.insertSelective(record);
    }

    @Override
    public void del(Integer faceGateId) {
        appFaceGateMapper.deleteLogicById(faceGateId);
    }

    @Override
    public String faceGateGrantEmdAdd(FaceGateGrantEmdAddParam request) {
        return null;
    }

    @Override
    public String faceGateGrantEmdImgAdd(FaceGateGrantEmdImgAddParam request) {
        return null;
    }

    @Override
    public String faceGateGrantEmdAuth(FaceGateGrantEmdAuthParam request) {
        return null;
    }

    @Override
    public void faceGateBatchGrantEmpAuth(AppFaceGateGrantEmpParam request) {

    }

    @Override
    public void faceGateRevokeEmp(AppFaceGateGrantEmpParam request) {

    }

    @Override
    public String deviceAuthorizationPerson(String deviceKey, String name, String imgUrl) {
        return null;
    }

    @Override
    public String deviceAuthorizationCancel(String deviceKey, String personGuid) {
        return null;
    }

    @Override
    public void openDoor(String deviceKey) {

    }

    @Override
    public void sync(Integer faceGateId) {

    }

    @Override
    public String getToken() {
        return null;
    }
}
